package main.observer;

import java.util.ArrayList;
import java.util.List;

public class DataSubject implements Observable {

    private int degree;
    private int humidity;
    private int pressure;

    private List<Observer> observers;

    public DataSubject() {

	observers = new ArrayList<Observer>();
    }

    public void setMeasurementData(int degree, int hummidity, int pressure) {

	this.degree = degree;
	this.humidity = hummidity;
	this.pressure = pressure;
	notifyObservers();
    }

    public int getDegree() {
	return degree;
    }

    public int getHumidity() {
	return humidity;
    }

    public int getPressure() {
	return pressure;
    }

    @Override
    public void registerObserver(Observer observer) {
	observers.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
	observers.remove(observer);
    }

    @Override
    public void notifyObservers() {
	for (Observer observer : observers) {
	    observer.update(this);
	}
    }

    @Override
    public void dataChanged() {
	notifyObservers();
    }
}
